<template>
	<view class="shoppingCart">
		<view v-if="userInfo.uid">
			<view class="box">
				<view>申请</view>
				<view class="box_word">代理</view>
			</view>
			<view class="box">
				<view>名称</view>
				<view class="box_word">
					<input placeholder="请输入" type="text" v-model="form.name" />
				</view>
			</view> 
			<view class="box">
				<view>地址</view>
				<view class="box_word">
					<input placeholder="请输入" type="text" v-model="form.address" />
				</view>
			</view>
			<view class="box">
				<view>电话</view>
				<view class="box_word">
					<input placeholder="请输入" type="text" v-model="form.phone" />
				</view>
			</view>
			<view class="btnd" @click="sqbtn">
				申请
			</view>
			<view class="btnx" @click="goback">
				返回
			</view>
		</view>
		<Authorization v-else />
	</view>
</template>

<script>
	import {
		handleUrlParam
	} from '@/utils'
	import {
		jxsInfodealer
	} from "../../../api/order.js"
	import {
		mapGetters,
	} from 'vuex'
	import {
		login,
		authorize
	} from '@/utils'
	import Authorization from "@/pages/authorization/index";
 
	export default {
		data() {
			return {
				form: {
					pid: "",
					name: "",
					address: "",
					phone: "",
				},
				isTrue: false,
				test: "",
				test1: "",
				isonload: false
			}
		},
		components: {
			Authorization
		},

		computed: mapGetters(["userInfo", "token"]),
		onLoad(options) {

			if (handleUrlParam(decodeURIComponent(options.q)).pid) {
				this.form.pid = handleUrlParam(decodeURIComponent(options.q)).pid
				this.isonload = true
			} else {
			
				this.isonload = false
			}
		},
		onShow() {
			console.log(2);
			wx.onAppShow((res) => {
				console.log("--res--");
				console.log(res); 
			})

			console.log("---2----");
			if (!this.isonload) {
				console.log(22);
				this.form.pid = this._route.query.pid
			}


		},
		methods: {
			async sqbtn() {
				// this.$forceUpdate()
	
				if (this.form.name == '') {
					uni.showToast({
						title: "名称必填", 
						icon: "none",
						duration: 2000
					})
					return
				}
				
				if(this.form.address.length>=18){
					uni.showToast({
						title: "地址长度18个字符内", 
						icon: "none",
						duration: 2000
					})
					return
				}
				
				if (!(/^[1]([3-9])[0-9]{9}$/.test(this.form.phone))) {
					uni.showToast({
						title: "电话不正确",
						icon: "none",
						duration: 2000
					})
					return
				}
				let _this = this
				let res = await jxsInfodealer(this.form)
				if (res.status != 200) {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 2000
					})
				} else {
					uni.showModal({
						title: "审核中",
						success: _this.goback(),
						
					})
				}

				// 		jxsInfodealer(this.form).then(res => {
				// 			this.test=JSON.stringify(res)
				// 			if (res.status != 200) {
				// 				uni.showToast({
				// 					title: res.msg,
				// 					icon: 'none',
				// 					duration: 2000
				// 				})

				// 			} else { 
				// 			uni.showModal({
				// 				title: "申请成功",
				// 				success:_this.goback(),

				// 			})
				// 			}  
				// 		})
			},
			goback() {
				uni.switchTab({
					url: "/pages/home/index"
				})
			},
		}
	}
</script>

<style scoped lang="less">
	.test {
		overflow: auto;
		border-bottom: 1upx solid #000000;
	}

	.box {
		width: 690upx;
		height: 70upx;
		margin: 0 auto;
		display: flex;
		justify-content: space-between;
		text-align: center;
		border-bottom: 1px solid rgba(0, 0, 0, 0.1);
		margin-top: 30upx;
	}

	.box_word {
		font-size: 17 upx;

		input {
			width: 100%;
			text-align: right;
		}

		// color: #0000004D;


	}

	.bzitem {
		width: 690upx;
		height: 270upx;
		margin: 0 auto;
		background-color: #EFEFF4;
		color: #282828;
		padding: 20upx;
	}

	.btnd {
		width: 300upx;
		height: 70upx;
		margin: 20upx auto;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #07c160;
		border-radius: 20upx;
		color: #FFFFFF;
	}

	.btnx {

		width: 300upx;
		height: 70upx;
		margin: 10upx auto;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #ff0000;
		border-radius: 20upx;
		color: #FFFFFF;
	}
</style>
